package org.example.back.service.Forum;

import org.example.back.entity.Forum.ForumPost;
import org.example.back.mapper.Forum.ForumPostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ForumPostService {

    @Autowired
    private ForumPostMapper forumPostMapper;

    public int createPost(ForumPost post) {
        post.setCreatedAt(LocalDateTime.now());
        post.setUpdatedAt(LocalDateTime.now());
        post.setViews(0);
        post.setLikes(0);
        return forumPostMapper.insertPost(post);
    }

    public ForumPost getPostById(Long id) {
        return forumPostMapper.selectPostById(id);
    }

    public List<ForumPost> getAllPosts() {
        return forumPostMapper.selectAllPosts();
    }

    public void increaseViews(Long id) {
        forumPostMapper.updateViews(id);
    }

    public int deletePost(Long id) {
        return forumPostMapper.deletePostById(id);
    }
}

